Skip to content

Conversation

@OlhaZahoruiko
Copy link
Contributor

Fixes maykinmedia/commonground-api-common#142

Changes

[Describe the changes here]

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.92%. Comparing base (ff5f242) to head (270fa43).

Files with missing lines Patch % Lines
src/objects/utils/views.py 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #723      +/-   ##
==========================================
- Coverage   84.98%   84.92%   -0.06%     
==========================================
  Files         141      141              
  Lines        2843     2832      -11     
  Branches      224      222       -2     
==========================================
- Hits         2416     2405      -11     
  Misses        375      375              
  Partials       52       52              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

🐰 Bencher Report

Branchfeature/142-custom-exception-handlers
Testbedubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_by_object_type📈 view plot
🚷 view threshold
125.32 ms
(+0.14%)Baseline: 125.13 ms
131.39 ms
(95.38%)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_one_result📈 view plot
🚷 view threshold
23.66 ms
(+1.14%)Baseline: 23.39 ms
24.56 ms
(96.32%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_1📈 view plot
🚷 view threshold
312.56 ms
(+1.30%)Baseline: 308.54 ms
323.97 ms
(96.48%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_5📈 view plot
🚷 view threshold
307.91 ms
(-0.35%)Baseline: 309.00 ms
324.45 ms
(94.90%)
performance_test/tests/test_objects_list.py::test_objects_api_list_small_page_size_page_20📈 view plot
🚷 view threshold
133.96 ms
(-0.18%)Baseline: 134.21 ms
140.92 ms
(95.06%)
🐰 View full continuous benchmarking report in Bencher

response = self.client.get(self.url, {"type": objecttype_url})

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, since the response is consistent with other projects, with invalid_params, etc., you can use this method to get the errors from vng_api_common.tests import get_validation_errors.

You can apply this for all tests as well.

Comment on lines 87 to 91
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}

self.assertEqual(
response.json()["type"],
[
f"Select a valid object type. {objecttype_url} is not one of the available choices."
],
invalid_params["type"],
f"Select a valid object type. {objecttype_url} is not one of the available choices.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}
self.assertEqual(
response.json()["type"],
[
f"Select a valid object type. {objecttype_url} is not one of the available choices."
],
invalid_params["type"],
f"Select a valid object type. {objecttype_url} is not one of the available choices.",
self.assertEqual(
get_validation_errors(response, "type"),
{
"name": "type",
"code": "invalid_choice",
"reason": f"Select a valid object type. {objecttype_url} is not one of the available choices.",
},
)

Copy link
Contributor

@danielmursa-dev danielmursa-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good 👍

@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch from 5ee4377 to 0dd574b Compare February 10, 2026 11:55
@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch 2 times, most recently from 6de9948 to d42b42e Compare February 10, 2026 14:21
Copy link
Collaborator

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remarks about tests, looks good otherwise

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

🐰 Bencher Report

Branchfeature/142-custom-exception-handlers
Testbedubuntu-24.04
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_by_object_type📈 view plot
🚷 view threshold
110.73 ms
(-9.64%)Baseline: 122.54 ms
128.67 ms
(86.06%)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_one_result📈 view plot
🚷 view threshold
22.02 ms
(+2.41%)Baseline: 21.50 ms
22.58 ms
(97.53%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_1📈 view plot
🚷 view threshold
269.15 ms
(-9.19%)Baseline: 296.38 ms
311.20 ms
(86.49%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_5📈 view plot
🚷 view threshold
270.35 ms
(-8.64%)Baseline: 295.92 ms
310.71 ms
(87.01%)
performance_test/tests/test_objects_list.py::test_objects_api_list_small_page_size_page_20📈 view plot
🚷 view threshold
125.10 ms
(-2.80%)Baseline: 128.71 ms
135.14 ms
(92.57%)
🐰 View full continuous benchmarking report in Bencher


data = response.json()

invalid_params = {p["name"]: p for p in data["invalid_params"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invalid_params = {p["name"]: p for p in data["invalid_params"]}
error = get_validation_errors(response, "type")

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

data = response.json()
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OlhaZahoruiko I think you can use this method everywhere to get the error dict

@stevenbal should we also add the key for validations that are not provided? like here

raise serializers.ValidationError(message, code=code)

Suggested change
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}
error = get_validation_errors(response, "")

@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch from f26f6b6 to 178c973 Compare February 12, 2026 11:08
["Fields in the configured authorization are absent in the data: 'some'"],
data = response.json()

reasons = [p["reason"] for p in data["invalid_params"]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here:

Suggested change
reasons = [p["reason"] for p in data["invalid_params"]]
error = get_validation_errors(response, "")


data = response.json()

self.assertEqual(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(
error = get_validation_errors(response, "")
self.assertEqual(error["reason"]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forget this one

response.json(), ["Operator `lt` supports only dates and/or numeric values"]

data = response.json()
reasons = [p["reason"] for p in data["invalid_params"]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reasons = [p["reason"] for p in data["invalid_params"]]
error = get_validation_errors(response, "")


data = response.json()

self.assertEqual(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(
error = get_validation_errors(response, "")
self.assertEqual(

[
"'date' and 'registrationDate' parameters can't be used in the same request"
],
data["invalid_params"][0]["reason"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data["invalid_params"][0]["reason"],
error = get_validation_errors(response, "")
data["invalid_params"][0]["reason"],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also here

Comment on lines 879 to 886
self.assertEqual(
data["invalid_params"][0]["name"],
"date",
)
self.assertEqual(
data["invalid_params"][0]["reason"],
"Enter a valid date.",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(
data["invalid_params"][0]["name"],
"date",
)
self.assertEqual(
data["invalid_params"][0]["reason"],
"Enter a valid date.",
)
error = get_validation_errors(response, "date")

Comment on lines 927 to 934
self.assertEqual(
data["invalid_params"][0]["name"],
"registrationDate",
)
self.assertEqual(
data["invalid_params"][0]["reason"],
"Enter a valid date.",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(
data["invalid_params"][0]["name"],
"registrationDate",
)
self.assertEqual(
data["invalid_params"][0]["reason"],
"Enter a valid date.",
)
error = get_validation_errors(response, "registrationDate")

[
"'fields' query parameter has invalid or unauthorized values: 'someField'"
],
data["invalid_params"][0]["reason"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data["invalid_params"][0]["reason"],
error = get_validation_errors(response, "")
data["invalid_params"][0]["reason"],

@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch from 178c973 to ff73c5f Compare February 12, 2026 13:42

error = get_validation_errors(response, "")

self.assertIn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertIn(
self.assertEqual(

@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch from ff73c5f to 270fa43 Compare February 12, 2026 14:09
@stevenbal stevenbal merged commit 840e819 into master Feb 12, 2026
27 checks passed
@stevenbal stevenbal deleted the feature/142-custom-exception-handlers branch February 12, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow defining a mapping of exceptions to responses for exception_handler

4 participants